FROM alpine:3.20 as builder
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk update
RUN apk add --no-cache build-base gcc linux-headers pcre-dev zlib-dev openssl-dev
WORKDIR /builder
COPY . .
RUN tar -zxvf nginx-1.23.0.tar.gz && cd nginx-1.23.0 \
&& patch -p1 < ../patch/nginx.patch \
&& ./configure --add-module=../modules/auxiliary --add-module=../modules/nacos \
--with-http_ssl_module --with-http_v2_module \
&& make && make install

FROM alpine:3.20
WORKDIR /usr/local/nginx
COPY --from=builder /usr/local/nginx /usr/local/nginx
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
    && apk add --no-cache  pcre-dev zlib-dev openssl-dev && apk -v cache clean
RUN ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx \
        && mkdir -p /usr/local/nginx/logs && mkdir -p /usr/local/nginx/conf && mkdir -p /usr/local/nginx/html && mkdir -p /var/cache/nacos \
        && ln -sf /dev/stdout /usr/local/nginx/logs/access.log && ln -sf /dev/stderr /usr/local/nginx/logs/error.log \
        && addgroup -S -g 101 nginx && adduser -D -u 101 -h /var/cache/nginx -G nginx nginx
CMD ["nginx", "-g", "daemon off;"]
